package cn.itcast.n4_共享模型_管程;

import lombok.extern.slf4j.Slf4j;

import static cn.itcast.util.Sleeper.sleep;

/**
 * @program: juc
 * @description:
 * @author: flyduck
 * @create: 2024-09-14 14:24
 **/
@Slf4j(topic = "c.Test04_synchronized加在方法上_线程八锁_情况2")
public class Test04_synchronized加在方法上_线程八锁_情况2 {
    public static void main(String[] args) {
        Number2 number2 = new Number2();

        new Thread(() -> {
            log.debug("开始");
            number2.a();
        },"t1").start();

        new Thread(() -> {
            log.debug("开始");
            number2.b();
        },"t2").start();
    }
}

@Slf4j(topic = "c.Number2")
class Number2{
    public synchronized void a(){
        sleep(1);
        log.debug("1");
    }
    public synchronized void b(){
        log.debug("2");
    }
}
